<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas{
            border: 1px solid black;
            margin: 0 auto;
            display: block;
        }
    </style>
</head>
<body>
    <canvas width="400px" height="500px" id="myCanvas">
    </canvas>    
    <!-- 画布的起始点是左上角（0,0） -->
    <script>
        //获取画布
        //获取画笔
        var paint = myCanvas.getContext('2d');
        //起笔
        paint.beginPath();
        paint.lineWidth = 10;
        paint.lineJoin = 'round';
        paint.moveTo(100,100);
        paint.lineTo(50,50);
        paint.lineTo(100,50);
        paint.strokeStyle = 'black';   
        paint.closePath();     
        paint.stroke();

        // 对比一下线段的末端
        // paint.beginPath();
        // paint.lineWidth = 10;
        // paint.lineCap = 'butt'
        // paint.moveTo(50,50);
        // paint.lineTo(150,50);
        // paint.stroke();

        // paint.beginPath();
        // paint.lineWidth = 10;
        // paint.lineCap = 'round'
        // paint.moveTo(50,100);
        // paint.lineTo(150,100);
        // paint.stroke();


        // paint.beginPath();
        // paint.lineWidth = 10;
        // paint.lineCap = 'square'
        // paint.moveTo(50,150);
        // paint.lineTo(150,150);
        // paint.stroke();


        // paint.beginPath();
        // paint.moveTo(150,50);
        // paint.lineTo(150,200);
        // paint.lineWidth = 1;
        // paint.strokeStyle = 'pink';
        // paint.stroke();










        

    </script>
</body>
</html>